<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2022/6/9
 * Time: 上午10:31
 */

namespace app\test\controller;

use app\common\cachemodel\AppConfig;
use app\common\cachemodel\zl1_relation\zl1IdeaTag;
use app\common\lib\astrolog\Acg;
use app\common\lib\astrolog\AuthenticatePlayboy;
use app\common\lib\astrolog\DailyFortune;
use app\common\lib\astrolog\HowToWooHim;
use app\common\lib\astrolog\IdealLover;
use app\common\lib\horoscope\Horoscope;
use app\common\lib\horoscope\HoroscopeFortune;
use app\common\lib\ImgCompare;
use app\common\model\Recode;
use think\Controller;
use think\Db;

/**
 * 逻辑测试
 * Class TestLogic
 * @package app\test\controller
 */
class TestLogic extends Controller
{
    public function bazizeri()
    {
        $rid = input('rid/d', 0); // 4923624
        $uid = input('uid/d', 0);
        $date = input('date/s', date('Y-m-d'));
        if ($rid > 0)
        {
            $map = [
                'id' => $rid,
            ];
        } elseif ($uid > 0)
        {
            $map = [
                'uid' => $uid,
                'isself' => 1,
            ];
        } else
        {
            $map = [
                'uid' => 12345805,
                'isself' => 1,
                'status' => 1,
            ];
        }
        $recode = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($map)->field('id,uid,aid,isself,name,type,year,month,day,hour,minute,timezone,birth_country,birth_province,birth_city,live_country,live_province,live_city,comments,long_deg,long_min,ew,lat_deg,lat_min,ns,is_summer')->find();

        $timestamp = strtotime($date);
        $option = [
            'tid' => 1,
            'recode' => $recode,
            'start_time' => strtotime($date),
            'end_time' => strtotime('+800 day', $timestamp),
        ];
//        $option = [
//            'tid' => 25,
//            'recode' =>
//                [
//                    'id' => 4923644,
//                    'status' => '1',
//                    'name' => '太可怜了',
//                    'type' => '2',
//                    'year' => '1994',
//                    'month' => '10',
//                    'day' => '14',
//                    'hour' => '10',
//                    'minute' => '15',
//                    'timezone' => '8',
//                    'birth_country' => '北京市',
//                    'birth_province' => '北京市',
//                    'birth_city' => '朝阳区',
//                    'live_country' => '北京市',
//                    'live_province' => '北京市',
//                    'live_city' => '东城区',
//                    'comments' => '自己',
//                    'isself' => '1',
//                    'long_deg' => '116',
//                    'long_min' => '27',
//                    'ew' => '1',
//                    'lat_deg' => '39',
//                    'lat_min' => '56',
//                    'ns' => '1',
//                    'avatar' => '/uploads/20221117/59f3fe98d6a7b2d295f6fead668dcdc6.png',
//                    'is_summer' => '0',
//                    'or_day' => '14',
//                    'uid' => '12346663',
//                    'aid' => '4923958',
//                    'sun' => '7-10-200.5121356',
//                    'moon' => '11-3-318.7171643',
//                    'merc' => '8-11-214.9696902',
//                    'venu' => '8-12-227.996153',
//                    'mars' => '5-8-125.2200643',
//                    'jupi' => '8-12-227.710977',
//                    'satu' => '12-3-336.2627833',
//                    'non' => '8-12-225.9462382',
//                    'lili' => '2-6-51.0669989',
//                    'juno' => '8-11-224.1341926',
//                    'asc' => '9-1-245.5417656',
//                    'mc' => '6-10-171.9483054',
//                    'is_read' => '1',
//                ],
//            'start_time' => 1673539200,
//            'end_time' => 1676304000,
//        ];
//        $data = HoroscopeFortune::getInstance()->setRecord($recode)->setAdvance($date)->bazizeri($option);
        $rids = Db::table('wechat_backup_07_18_14_43_00.app_recode_cat')->where('cid', 151264)->column('rid');
        $rids = [4923208];
        $where['id'] = ['in', $rids];
        $recordList = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($where)->limit(200)->select();
        echo '<pre>';
        foreach ($recordList as $recode)
        {
            echo $recode['id'] . '<br/>';
            $data = HoroscopeFortune::getInstance()->setRecord($recode)->baziyongshen(['good_years' => [2022, 2023], 'bad_years' => [2005, 2006, 2007]]);
            print_r($data);
        }
    }

    public function acg2022()
    {
        $rid = input('rid/d', 0); // 4923624
        $uid = input('uid/d', 0);
        if ($rid > 0)
        {
            $map = [
                'id' => $rid,
            ];
        } elseif ($uid > 0)
        {
            $map = [
                'uid' => $uid,
                'isself' => 1,
            ];
        } else
        {
            $map = [
                'uid' => 12345805,
                'isself' => 1,
                'status' => 1,
            ];
        }
//        $recode = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($map)->field('id,uid,aid,isself,name,type,year,month,day,hour,minute,timezone,birth_country,birth_province,birth_city,live_country,live_province,live_city,comments,long_deg,long_min,ew,lat_deg,lat_min,ns,is_summer')->find();
        $rids = Db::table('wechat_backup_07_18_14_43_00.app_recode_cat')->where('cid', 151264)->column('rid');
//        $rids = [4923523];
        $where['id'] = ['in', $rids];
        $recordList = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($where)->limit(200)->select();

        $names = [
            'xingyun' => '幸运',
            'jiankang' => '健康',
            'shiye' => '事业',
            'taohua' => '桃花',
            'caifu' => '财富',
            'anju' => '安居',
            'shejiao' => '社交',
            'youle' => '游乐',
            'zhishi' => '知识',
            'caifu1' => '财富1',
            'caifu2' => '财富2',
            'caifu3' => '财富3',
            'caifu4' => '财富4',

            'gongzuo1' => '工作1',
            'gongzuo2' => '工作2',
            'gongzuo3' => '工作3',
            'gongzuo4' => '工作4',

            'hunlian1' => '婚恋1',
            'hunlian2' => '婚恋2',
            'hunlian3' => '婚恋3',
            'hunlian4' => '婚恋4',

            'jiankang1' => '健康1',
            'jiankang2' => '健康2',
            'jiankang3' => '健康3',
            'jiankang4' => '健康4',

            'xuexi1' => '学习1',
            'xuexi2' => '学习2',
            'xuexi3' => '学习3',
            'xuexi4' => '学习4',

            'xingyun1' => '幸运1',
            'xingyun2' => '幸运2',
            'xingyun3' => '幸运3',
            'xingyun4' => '幸运4',
        ];

        echo '<style>
        body {
            margin: 0;
            padding: 0;
        }
        table
        {
            border-collapse: collapse;
            margin: 0 auto;
            text-align: center;
        }
        table td, table th
        {
            border: 1px solid #cad9ea;
            color: #666;
            height: 30px;
        }
        table thead
        {
            position: sticky;
            position: -webkit-sticky;
            top: 0;
            z-index: 2;
        }
        table thead th {
            background: #84ffff;
            font-size: 12px;
        }
        table tbody tr:hover {
            background: #d5f5f5;
        }
        </style>';
        echo '<table border="1" cellspacing="0" cellpadding="10">';

        foreach ($recordList as $k1 => $recode)
        {
            $point = ['longitude' => 108.923611, 'latitude' => 34.540833];
            // 全国中心点：北纬 34度32分27秒，东经108度55分25秒
            $data = (new Acg())->getPointInfo2($recode, $point);
            if ($k1 === 0)
            {
                echo '<thead>';
                echo '<tr>';
                echo '<th>档案编号</th>';
                echo '<th>姓名</th>';
                echo '<th>目标点</th>';
                foreach ($data as $k2 => $v2)
                {
                    echo '<th>' . ($names[$k2] ?? '') . '</th>';
                }
                echo '</tr></thead><tbody>';
            }


            echo '<tr>';
            echo '<td>' . $recode['id'] . '</td>';
            echo '<td>' . $recode['name'] . '</td>';
            echo '<td>经度：' . $point['longitude'] . '<br/>纬度：' . $point['latitude'] . '</td>';

            foreach ($data as $k2 => $v)
            {
                if ($v > 0)
                {
                    $g = $v > 255 ? 255 : (int)$v;
                    $g = 255 - $g;
                    echo '<td  style="color: #666;background-color: rgb(0, ' . $g . ', 0)">' . sprintf('%.2f', $v) . '</td>';
                } elseif ($v < 0)
                {
                    $r = $v < -255 ? 255 : (int)($v * -1);
                    $r = 255 - $r;
                    echo '<td  style="color: #666;background-color: rgb(' . $r . ', 0 , 0)">' . sprintf('%.2f', $v) . '</td>';
//                    echo '<td bgcolor="#ff4500" style="color: #666;">' . sprintf('%.2f', $v) . '</td>';
                } else
                {
                    echo '<td>' . sprintf('%.2f', $v) . '</td>';
                }
            }
            echo '</tr>';
        }

        echo '</tbody></table>';
    }

    public function baziwaige()
    {
        $type = input('type/s', 'waige');
        $rid = input('rid/d', 0); // 4923624
        $uid = input('uid/d', 0);
        $time = input('year/s', date('Y-m-d'));
        if ($rid > 0)
        {
            $map = [
                'id' => $rid,
            ];
        } elseif ($uid > 0)
        {
            $map = [
                'uid' => $uid,
                'isself' => 1,
            ];
        } else
        {
            $map = [
                'uid' => 12345805,
                'isself' => 1,
                'status' => 1,
            ];
        }

        echo '<pre>';
        $timestamp = strtotime($time);
//        $recode = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($map)->field('id,uid,aid,isself,name,type,year,month,day,hour,minute,timezone,birth_country,birth_province,birth_city,live_country,live_province,live_city,comments,long_deg,long_min,ew,lat_deg,lat_min,ns,is_summer')->find();
//        $bazi = Horoscope::getInstance([
//            'recode' => $recode,
//            'time_start' => 23,
//            'time_type' => 0,
//            'advance' => [
//                'year' => date('Y', $timestamp) * 1,
//                'month' => date('m', $timestamp) * 1,
//                'day' => date('d', $timestamp) * 1,
//                'hour' => date('H', $timestamp) * 1,
//                'minute' => date('i', $timestamp) * 1,
//                'timezone' => 8,
//                'is_summer' => 0,
//            ]
//        ])->getUserData2();
//        $data = Horoscope::getInstance()->baziwaige($bazi['bazi']);
//
//        print_r($data);

        $rids = Db::table('wechat_backup_07_18_14_43_00.app_recode_cat')->where('cid', 151264)->column('rid');
//        $rids = [4921749];
        $where['id'] = ['in', $rids];
        $recordList = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($where)->limit(200)->select();

        echo '<table border="1" cellspacing="0" cellpadding="10">';
        echo '<thead>';
        echo '<tr>';
        echo '<th>档案编号</th>';
        echo '<th>姓名</th>';
        echo '<th>八字</th>';
        echo '<th>命宫</th>';
        echo '<th>外格</th>';
        echo '<th>天干关系</th>';
        echo '<th>地支关系</th>';
        echo '</tr></thead><tbody>';

        $configData = config('bazi.waige');
        foreach ($recordList as $recode)
        {
            if ($recode['id'] === 4921749)
            {
                $ccc = 1;
            }
//            $recode['year'] = 1997;
//            $recode['month'] = 11;
//            $recode['day'] = 25;
//            $recode['hour'] = 6;
//            $recode['minute'] = 10;
            $instance = Horoscope::getInstance([
                'recode' => $recode,
                'time_start' => 23,
                'time_type' => 0,
//                'shensha' => 2,
                'advance' => [
                    'year' => date('Y', $timestamp) * 1,
                    'month' => date('m', $timestamp) * 1,
                    'day' => date('d', $timestamp) * 1,
                    'hour' => date('H', $timestamp) * 1,
                    'minute' => date('i', $timestamp) * 1,
                    'timezone' => 8,
                    'is_summer' => 0,
                ]
            ]);
            $bazi = $instance->data['bazi'];
            $waigeList = $instance->baziwaige($bazi);
            $neigeList = $instance->bazineige($bazi);
            $guanxiList = $instance->baziGuanxi($bazi);
            $baziMinggong = $instance->baziMinggong($bazi);
//            print_r($recode['id']);
//            $geju72 = $instance->gejupanding($bazi);
            print_r($waigeList);
//            $userData3 = $instance->getUserData3();
//            echo json_encode($userData3);
//            print_r($userData3['shensha']['shensha']);
//            $userData2 = $instance->getUserData();

//            $bazijiedu = HoroscopeFortune::getInstance()->setAdvance(date('Y-m-d'))->setRecord($recode)->bazijiedu();
//            print_r($bazijiedu);
//            exit;

            echo '<tr>';
            echo '<td>' . $recode['id'] . '</td>';
            echo '<td>' . $recode['name'] . '</td>';
            echo '<td>' . implode('', $bazi) . '</td>';
            echo '<td>' . implode('', $baziMinggong) . '</td>';
            $name = '';
            if (!empty($waigeList))
            {
                foreach ($waigeList as $k)
                {
                    $name .= $configData[$k]['name'] . '、';
                }
                $name = rtrim($name, '、');
            }
            echo '<td>' . $name . '</td>';

            $tggx = '';
            if (!empty($guanxiList['tiangan_guanxi']))
            {
                foreach ($guanxiList['tiangan_guanxi'] as $k1 => $v1)
                {
                    $tggx .= $v1['name'] . '、';
                }
                $tggx = rtrim($tggx, '、');
            }
            echo '<td>' . $tggx . '</td>';

            $dzgx = '';
            if (!empty($guanxiList['dizhi_guanxi']))
            {
                foreach ($guanxiList['dizhi_guanxi'] as $k1 => $v1)
                {
                    $dzgx .= $v1['name'] . '、';
                }
                $dzgx = rtrim($dzgx, '、');
            }
            echo '<td>' . $dzgx . '</td>';


            echo '</tr>';
        }

        echo '</tbody>';
    }

    public function year2022()
    {
        $rid = input('rid/d', 0); // 4923624
        $uid = input('uid/d', 0);
        $year = input('year/d', (int)date('Y'));
        $time = $year . '-01-01';
        if ($rid > 0)
        {
            $map = [
                'id' => $rid,
            ];
        } elseif ($uid > 0)
        {
            $map = [
                'uid' => $uid,
                'isself' => 1,
            ];
        } else
        {
            $map = [
                'uid' => 12345805,
                'isself' => 1,
                'status' => 1,
            ];
        }
        $recode = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($map)->field('id,uid,aid,isself,name,type,year,month,day,hour,minute,timezone,birth_country,birth_province,birth_city,live_country,live_province,live_city,comments,long_deg,long_min,ew,lat_deg,lat_min,ns,is_summer')->find();

        echo '<pre>';
//        echo '<table border="1" cellspacing="0" cellpadding="10">';
//        echo '<thead>';
//        echo '<tr>';
//        echo '<th>姓名</th>';
//        echo '<th>八字</th>';
//        echo '<th>年份</th>';
//        echo '<th>大运</th>';
//        echo '<th>流年</th>';
//        echo '<th>恋爱婚姻</th>';
//        echo '<th>往来出行</th>';
//        echo '<th>金钱财富</th>';
//        echo '<th>工作事业</th>';
//        echo '<th>考试求学</th>';
//        echo '<th>人际关系</th>';
//        echo '<th>身心健康</th>';
//        echo '<th>家运亲情</th>';
////        echo '<th>亲和</th>';
//        echo '</tr>';
//        echo '<thead><tbody>';
        // 2022年 年运升级逻辑测试
        $horoscopeFortune = HoroscopeFortune::getInstance()->setRecord($recode);
//        for ($i = 0; $i < 20; $i++)
//        {
//            $y = $year + $i;
//            $d = $horoscopeFortune->setAdvance($y . '-06-30')->nianyunLeidaTouTu(true);
////            print_r($d);
//
//            echo '<tr>';
//            echo '<td>' . $recode['name'] . '</td>';
//            echo '<td>' . implode('', $horoscopeFortune->getBazi()) . '</td>';
//            echo '<td>' . $y . '</td>';
//            echo '<td>' . implode('', $horoscopeFortune->getDayun()) . '</td>';
//            echo '<td>' . implode('', $horoscopeFortune->getLiunian()) . '</td>';
//            foreach ($d['leida'] as $k1 => $v1)
//            {
//                echo '<td>' . sprintf('%.2f', $v1['score']) . '</td>';
//            }
//
//            echo '<tr>';
//
////            $d = $horoscopeFortune->setAdvance($y . '-06-01')->qinheScore(2);
////            echo '<tr>';
////            echo '<td>' . $recode['name'] . '</td>';
////            echo '<td>' . implode('', $horoscopeFortune->getBazi()) . '</td>';
////            echo '<td>' . $y . '</td>';
////            echo '<td>' . implode('', $horoscopeFortune->getDayun()) . '</td>';
////            echo '<td>' . implode('', $horoscopeFortune->getLiunian()) . '</td>';
////            echo '<td>' . sprintf('%.2f', $d) . '</td>';
////            echo '</tr>';
//
//        }
//        echo '</tbody>';
//        echo '';
//        echo '</table>';

//        $d = HoroscopeFortune::getInstance()->setRecord($recode)->setAdvance(date('Y'))->nianyunQifu();
//        echo $recode['name'] . ' ';
//        echo implode('', $horoscopeFortune->getBazi());
//        echo '<br/>';
//
//        print_r($d);
//        echo '<thead>';
//        echo '<tr>';
//        echo '<th>姓名</th>';
//        echo '<th>八字</th>';
//        echo '<th>年份</th>';
//        echo '<th>大运</th>';
//        echo '<th>流年</th>';
//        echo '</tr>';
//        echo '<thead><tbody>';
//        echo '<td rowspan="11">' . $recode['name'] . '</td>';
//        echo '<td rowspan="11">' . implode('', $horoscopeFortune->getBazi()) . '</td>';
//        foreach ($d['dayun'] as $k1 => $v1)
//        {
//
//        }
//        echo '</tbody>';
//        echo '</table>';

//        $d = HoroscopeFortune::getInstance()->setAdvance($year . '-06-30')->nianyunLeidaTouTu();
        $d = HoroscopeFortune::getInstance()->setAdvance($year . '-06-30')->renshengjieduan();
//        $d = HoroscopeFortune::getInstance()->setAdvance($year . '-06-30')->liunianShaixuan();
//        $d = HoroscopeFortune::getInstance()->setRecord($recode)->setAdvance(date('Y'))->nianyunQifu();
        print_r($d);
//
//        $rids = Db::table('wechat_backup_07_18_14_43_00.app_recode_cat')->where('cid', 151264)->column('rid');
////        $rids = [4923523];
//        $where['id'] = ['in', $rids];
//        $recordList = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($where)->limit(200)->select();

    }

    public function testbazi2022()
    {
        $rid = input('rid/d', 0); // 4923624
        $uid = input('uid/d', 0);
        $year = input('year/d', (int)date('Y'));
        $time = $year . '-01-01';
//        $rid= 0;
        if ($rid > 0)
        {
            $map = [
                'id' => $rid,
            ];
        } elseif ($uid > 0)
        {
            $map = [
                'uid' => $uid,
                'isself' => 1,
            ];
        } else
        {
            $map = [
                'uid' => 12345805,
                'isself' => 1,
                'status' => 1,
            ];
        }
        $recode = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($map)->field('id,uid,aid,isself,name,type,year,month,day,hour,minute,timezone,birth_country,birth_province,birth_city,live_country,live_province,live_city,comments,long_deg,long_min,ew,lat_deg,lat_min,ns,is_summer')->find();

        // 2022年 年运升级逻辑测试
        $data = HoroscopeFortune::getInstance()->setAdvance($time)->setRecord($recode)->init();

        $rids = Db::table('wechat_backup_07_18_14_43_00.app_recode_cat')->where('cid', 151264)->column('rid');
//        $rids = [4923523];
        $where['id'] = ['in', $rids];
        $recordList = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($where)->limit(200)->select();

        echo '<style>
        body {
            margin: 0;
            padding: 0;
        }
        table
        {
            border-collapse: collapse;
            margin: 0 auto;
            text-align: center;
        }
        table td, table th
        {
            border: 1px solid #cad9ea;
            color: #666;
            height: 30px;
        }
        table thead
        {
            position: sticky;
            position: -webkit-sticky;
            top: 0;
            z-index: 2;
        }
        table thead th {
            background: #84ffff;
            font-size: 12px;
        }
        table tbody tr:hover {
            background: #d5f5f5;
        }
        </style>';
        echo '<table border="1" cellpadding="10" cellspacing="0">';
        echo '<thead><tr>';
        echo '<th rowspan="2">昵称</th>';
        echo '<th rowspan="2">八字</th>';
        echo '<th rowspan="2">大运</th>';
        echo '<th rowspan="2">亲和等级</th>';
        echo '<th rowspan="2">过旺</th>';

//        echo '<th colspan="2">父亲</th>';
//        echo '<th colspan="2">母亲</th>';
//        echo '<th colspan="2">子女</th>';
//        echo '<th colspan="2">兄弟姐妹</th>';
//        echo '<th colspan="2">婚恋</th>';
//        echo '<th colspan="2">工作1</th>';
//        echo '<th colspan="2">工作2</th>';
//        echo '<th colspan="2">灾病</th>';
//        echo '<th colspan="2">财富</th>';
//        echo '<th colspan="2">学业</th>';

        echo '<th rowspan="2">恋爱婚姻</th>';
        echo '<th rowspan="2">往来出行</th>';
        echo '<th rowspan="2">金钱财富</th>';
        echo '<th rowspan="2">工作事业</th>';
        echo '<th rowspan="2">考试求学</th>';
        echo '<th rowspan="2">人际关系</th>';
        echo '<th rowspan="2">身心健康</th>';
        echo '<th rowspan="2">家运亲情</th>';


        echo '<th rowspan="2">天干</th>';
        echo '<th rowspan="2">生</th>';
        echo '<th rowspan="2">克</th>';
        echo '<th rowspan="2">命</th>';
        echo '<th rowspan="2">健康值</th>';
        echo '<th rowspan="2">实力值</th>';
        echo '<th rowspan="2">综合实力值</th>';
        echo '<th rowspan="2">真实实力值</th>';
        echo '</tr>';
        echo '<tr>';
//        echo '<th>动态</th><th>负面</th>';
//        echo '<th>动态</th><th>负面</th>';
//        echo '<th>动态</th><th>负面</th>';
//        echo '<th>动态</th><th>负面</th>';
//        echo '<th>动态</th><th>负面</th>';
//        echo '<th>动态</th><th>负面</th>';
//        echo '<th>动态</th><th>负面</th>';
//        echo '<th>动态</th><th>负面</th>';
//        echo '<th>动态</th><th>负面</th>';
//        echo '<th>动态</th><th>负面</th>';
        echo '</tr>';
        echo '</thead><tbody>';
        foreach ($recordList as $k1 => $v1)
        {
            $d = HoroscopeFortune::getInstance()->setRecord($v1)->init();
            echo '<tr>';
            echo '<td rowspan="11">' . $v1['name'] . '</td>';
            echo '<td rowspan="11">' . $d['bazi'] . '</td>';
            echo '<td rowspan="11">' . $d['dayun'] . '</td>';
            echo '<td rowspan="11">' . $d['qinhe'] . '</td>';
            echo '<td rowspan="11">' . $d['guowang'] . '</td>';

//            echo '<td rowspan="11">' . $d['zhuti']['fuqin']['dongtai'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['fuqin']['fumian'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['muqin']['dongtai'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['muqin']['fumian'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['zinv']['dongtai'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['zinv']['fumian'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['xiongmei']['dongtai'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['xiongmei']['fumian'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['hunlian']['dongtai'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['hunlian']['fumian'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['gongzuo1']['dongtai'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['gongzuo1']['fumian'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['gongzuo2']['dongtai'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['gongzuo2']['fumian'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['zaibing']['dongtai'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['zaibing']['fumian'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['caifu']['dongtai'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['caifu']['fumian'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['xueye']['dongtai'] . '</td>';
//            echo '<td rowspan="11">' . $d['zhuti']['xueye']['fumian'] . '</td>';

            echo '<td rowspan="11">' . $d['leida'][0]['score'] . '</td>';
            echo '<td rowspan="11">' . $d['leida'][1]['score'] . '</td>';
            echo '<td rowspan="11">' . $d['leida'][2]['score'] . '</td>';
            echo '<td rowspan="11">' . $d['leida'][3]['score'] . '</td>';
            echo '<td rowspan="11">' . $d['leida'][4]['score'] . '</td>';
            echo '<td rowspan="11">' . $d['leida'][5]['score'] . '</td>';
            echo '<td rowspan="11">' . $d['leida'][6]['score'] . '</td>';
            echo '<td rowspan="11">' . $d['leida'][7]['score'] . '</td>';


            echo '</tr>';
            foreach ($d['health'] as $k2 => $v2)
            {
                echo '<tr>';
                echo '<td>' . $k2 . '</td>';
                echo '<td>' . sprintf('%.2f', $v2['sheng']) . '</td>';
                echo '<td>' . sprintf('%.2f', $v2['ke']) . '</td>';
                echo '<td>' . sprintf('%.2f', $v2['ming']) . '</td>';
                echo '<td>' . sprintf('%.2f', $v2['jiankang']) . '</td>';
                echo '<td>' . sprintf('%.2f', $v2['shili']) . '</td>';
                echo '<td>' . sprintf('%.2f', $v2['zong_shili']) . '</td>';
                echo '<td>' . sprintf('%.2f', $v2['zhen_shili']) . '</td>';
                echo '</tr>';
            }
//            echo '<tr>';

//            echo '</tr>';
        }
        echo '</tbody></table>';
    }

    public function testSensitivity()
    {
        $rid = input('rid/d', 0); // 4923624
        $uid = input('uid/d', 0);
        $time = input('time/s', date('Y-m-d'));
        $changeType = input('change_type/d', 1);
        $limit = input('limit/d', 0);

        if ($rid > 0)
        {
            $map = [
                'id' => $rid,
            ];
        } elseif ($uid > 0)
        {
            $map = [
                'uid' => $uid,
                'isself' => 1,
            ];
        } else
        {
            $map = [
                'uid' => 12345805,
                'isself' => 1,
                'status' => 1,
            ];
        }
        $recode = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($map)->field('id,uid,aid,isself,name,type,year,month,day,hour,minute,timezone,birth_country,birth_province,birth_city,live_country,live_province,live_city,comments,long_deg,long_min,ew,lat_deg,lat_min,ns,is_summer')->find();
        $rids = Db::table('wechat_backup_07_18_14_43_00.app_recode_cat')->where('cid', 151264)->column('rid');
//        $rids = [4923523];
        $where['id'] = ['in', $rids];
        $recordList = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($where)->limit(200)->select();

//        $time = date('Y-m-d');
//        $time = '2023-09-01 12:00:00';
        if (strlen($time) === 10)
        {
            $time .= ' 00:00:00';
        }
        $timestamp = strtotime($time);

        $calcStartTime = microtime(true);
        $data = DailyFortune::getInstance()
            ->setAdvance($time)
            ->setMainRecord($recode)
            ->setChangeType($changeType)
            ->setDoingLimit($limit)
//            ->setOtherRecordList($recordList)
            ->sensitivity();
        $calcEndTime = microtime(true);
        $beforeDay = date('Y-m-d', strtotime('-1 day', $timestamp));
        $afterDay = date('Y-m-d', strtotime('+1 day', $timestamp));
        echo '计算耗时：' . ($calcEndTime - $calcStartTime) . 's <br/>';
        echo '<a href="/test/test_logic/testSensitivity?time=' . $beforeDay . '&change_type=' . $changeType . '&limit=' . $limit . '">' . $beforeDay . '</a>';
        echo '&nbsp;&nbsp;&nbsp;&nbsp;' . date('Y-m-d', $timestamp);
        echo '&nbsp;&nbsp;&nbsp;&nbsp;<a href="/test/test_logic/testSensitivity?time=' . $afterDay . '&change_type=' . $changeType . '&limit=' . $limit . '">' . $afterDay . '</a>';
        echo '<pre>';
        print_r($data);
    }

    public function daily_fortune()
    {
        $map = [
            'uid' => 12345805,
            'isself' => 1,
            'status' => 1,
        ];
        $map = [
            'uid' => 12345805,
            'id' => 4923526,// 4923209  4923480  4923526:阿黑
            'status' => 1,
        ];
        $recode = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($map)->field('id,uid,aid,isself,name,type,year,month,day,hour,minute,timezone,birth_country,birth_province,birth_city,live_country,live_province,live_city,comments,long_deg,long_min,ew,lat_deg,lat_min,ns,is_summer')->find();
        $rids = Db::table('wechat_backup_07_18_14_43_00.app_recode_cat')->where('cid', 151264)->column('rid');
//        $rids = [4923523];
        $where['id'] = ['in', $rids];
        $recordList = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($where)->limit(200)->select();

        $time = date('Y-m-d');
//        $time = '2023-10-20 12:00:00';
        $timestamp = strtotime($time);
        echo '<h2>主档案：' . $recode['name'] . '  </h2> ';
        for ($i = $timestamp; $i < $timestamp + 10 * 86400; $i += 86400)
        {
            $data = DailyFortune::getInstance()
                ->setAdvance(date('Y-m-d', $i))
                ->setMainRecord($recode)
                ->setOtherRecordList($recordList)
                ->luckyPartner();

            echo '<table border="1" cellspacing="0" cellpadding="5" style="float: left;">
                    <thead>
                        <tr>
                            <th colspan="3">时间：' . date('Y-m-d', $i) . '</th>
                        </tr>
                        <tr>
                            <th>昵称</th>
                            <!--<th>档案ID</th>-->
                            <th>善待值</th>
                        </tr>
                    </thead><tbody>';
            foreach ($data as $d)
            {
                echo '<tr>';
                echo '<td>' . $d['name'] . '</td>';
//                echo '<td>' . $d['rid'] . '</td>';
                echo '<td>' . $d['score'] . '</td>';
                echo '</tr>';
            }
            echo '</tbody></table>';
        }

//        $data = EverydayFortune::getInstance()
//            ->setAdvance($time)
//            ->setMainRecord($recode)
//            ->setOtherRecordList($recordList)
//            ->luckyPartner();
//
//        echo '<table border="1" cellspacing="0" cellpadding="5"><thead><th colspan="3">时间：' . $time . '</th><tr><th>昵称</th><th>档案ID</th><th>善待值</th></tr></thead><tbody>';
//        foreach ($data as $d)
//        {
//            echo '<tr>';
//            echo '<td>' . $d['rid'] . '</td>';
//            echo '<td>' . $d['name'] . '</td>';
//            echo '<td>' . $d['score'] . '</td>';
//            echo '</tr>';
//        }
//        echo '</tbody></table>';
//
//        $time = '2022-09-02';
//
//        $data = EverydayFortune::getInstance()
//            ->setAdvance($time)
//            ->luckyPartner();
//
//        echo '<table border="1" cellspacing="0" cellpadding="5"><thead><th colspan="3">时间：' . $time . '</th><tr><th>昵称</th><th>档案ID</th><th>善待值</th></tr></thead><tbody>';
//        foreach ($data as $d)
//        {
//            echo '<tr>';
//            echo '<td>' . $d['rid'] . '</td>';
//            echo '<td>' . $d['name'] . '</td>';
//            echo '<td>' . $d['score'] . '</td>';
//            echo '</tr>';
//        }
//        echo '</tbody></table>';
//
//        $time = '2022-09-03';
//
//        $data = EverydayFortune::getInstance()
//            ->setAdvance($time)
//            ->luckyPartner();
//
//        echo '<table border="1" cellspacing="0" cellpadding="5"><thead><th colspan="3">时间：' . $time . '</th><tr><th>昵称</th><th>档案ID</th><th>善待值</th></tr></thead><tbody>';
//        foreach ($data as $d)
//        {
//            echo '<tr>';
//            echo '<td>' . $d['rid'] . '</td>';
//            echo '<td>' . $d['name'] . '</td>';
//            echo '<td>' . $d['score'] . '</td>';
//            echo '</tr>';
//        }
//        echo '</tbody></table>';
//
//        $time = '2022-09-04';
//
//        $data = EverydayFortune::getInstance()
//            ->setAdvance($time)
//            ->luckyPartner();
//
//        echo '<table border="1" cellspacing="0" cellpadding="5"><thead><th colspan="3">时间：' . $time . '</th><tr><th>昵称</th><th>档案ID</th><th>善待值</th></tr></thead><tbody>';
//        foreach ($data as $d)
//        {
//            echo '<tr>';
//            echo '<td>' . $d['rid'] . '</td>';
//            echo '<td>' . $d['name'] . '</td>';
//            echo '<td>' . $d['score'] . '</td>';
//            echo '</tr>';
//        }
//        echo '</tbody></table>';
    }

    public function bazi()
    {
        $rid = input('rid/d', 4923229);
        $recode = (new Recode())->getRecode(['id' => $rid]);
        if (!$recode)
        {
            return show(config('code.error'), '档案不存在');
        }

        // 初始化八字数据，档案的八字信息
        $now = time();
        $advance = [
            'year' => date('Y', $now) * 1,
            'month' => date('m', $now) * 1,
            'day' => date('d', $now) * 1,
            'hour' => date('H', $now) * 1,
            'minute' => date('i', $now) * 1,
            'timezone' => 8,
            'is_summer' => 0,
        ];

        $rids = Db::table('wechat_backup_07_18_14_43_00.app_recode_cat')->where('cid', 151264)->column('rid');
//        $rids = [4923480];
        $where['id'] = ['in', $rids];
        $recordList = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($where)->limit(200)->select();

        echo '<table border="1" cellspacing="0" cellpadding="5"><thead><th>昵称</th><th>八字</th><th>木</th><th>火</th><th>土</th><th>金</th><th>水</th></thead><tbody>';
        foreach ($recordList as $recode)
        {
            echo '<tr>';
            echo '<td>' . $recode['name'] . '</td>';
            $score = Horoscope::getInstance(['recode' => $recode, 'advance' => $advance])->getWuxingWang();
            echo '<td>' . $score[0] . '</td>';
            echo '<td>' . $score[1] . '</td>';
            echo '<td>' . $score[2] . '</td>';
            echo '<td>' . $score[3] . '</td>';
            echo '<td>' . $score[4] . '</td>';
            echo '</tr>';
        }
        echo '</tbody></table>';
    }

    /**
     * 图片相似度检测Demo
     */
    public function compare()
    {
        $imgs = [
//            ROOT_PATH . 'img_compare_demo/1.jpeg',
//            ROOT_PATH . 'img_compare_demo/2.jpeg',
//            ROOT_PATH . 'img_compare_demo/3.jpeg',
//            ROOT_PATH . 'img_compare_demo/4.jpeg',
//            ROOT_PATH . 'img_compare_demo/5.jpg',
//            ROOT_PATH . 'img_compare_demo/6.jpeg',
            'https://oss.goddessxzns.com/test/img_compare_demo/1.jpeg',
            'https://oss.goddessxzns.com/test/img_compare_demo/2.jpeg',
            'https://oss.goddessxzns.com/test/img_compare_demo/3.jpeg',
            'https://oss.goddessxzns.com/test/img_compare_demo/4.jpeg',
            'https://oss.goddessxzns.com/test/img_compare_demo/5.jpg',
            'https://oss.goddessxzns.com/test/img_compare_demo/6.jpeg',
        ];

        $img = new ImgCompare();

        echo '<table border="1" cellspacing="0" cellpadding="10">';
        echo '<tr style="position: sticky;position: -webkit-sticky;top: 0;z-index: 2;background-color: #cccccc;"><td style="text-align: center;">图片1</td><td style="text-align: center;">图片2</td><td>相似度</td></tr>';
        foreach ($imgs as $k1 => $v1)
        {
            foreach ($imgs as $k2 => $v2)
            {
                if ($k1 < $k2)
                {
                    echo '<tr>';
                    $count = $img->compare($v1, $v2);
                    echo '<td style="text-align: center;"><img src="' . $v1 . '" style="width: 200px;border: 1px solid #000;"/><p>' . $v1 . '</p></td>';
                    echo '<td style="text-align: center;"><img src="' . $v2 . '" style="width: 200px;border: 1px solid #000;"/><p>' . $v2 . '</p></td>';
                    echo '<td>' . $count . '</td>';
                    echo '</tr>';
                }
            }
        }

        echo '</table>';
    }

    public function woo()
    {
        $rid1 = input('rid1/d', 4923229);// Seunk
        $rid2 = input('rid2/d', 4921747);// 奇
        $map = [
            'id' => ['in' => [$rid1, $rid2]]
        ];
//        $recode1 = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where('id', $rid1)->find();
//        $recode2 = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where('id', $rid2)->find();
//        $data = HowToWooHim::getInstance()->setUserRecord([$recode1, $recode2])->free();
//        $data = HowToWooHim::getInstance()->setUserRecord([$recode1, $recode2])->init();
//        $data = AuthenticatePlayboy::getInstance()->setUserRecord($recode1)->free();
//        $data = AuthenticatePlayboy::getInstance()->setUserRecord($recode1)->init();
//        echo json_encode($data);


        // 根据档案袋ID过滤
        $rids = Db::table('wechat_backup_07_18_14_43_00.app_recode_cat')->where('cid', 151264)->column('rid');
//        $rids = [4921757];//   4923481
        $where['id'] = ['in', $rids];
        $recordList = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($where)->limit(200)->select();

        $res = [];
        foreach ($recordList as $recode)
        {
            $playboy = AuthenticatePlayboy::getInstance()->setUserRecord($recode)->free();
            $woo = HowToWooHim::getInstance()->setUserRecord([$recode, $recode])->free();
//            if ($recode['name'] === '邢昊聪' || $recode['name'] === '闵淑衡')
//            {
//                $res[] = ['name' => $recode['name'], 'probability' => 99, 'difficulty' => $woo['difficulty'], 'rival' => $woo['rival']];
//            } else
//            {
            $res[] = [
                'name' => $recode['name'],
                'probability' => $playboy['probability'],
                'astro_score' => number_format($playboy['astro_score'], 2),
                'bazi_score' => number_format($playboy['bazi_score'], 2),
                'score' => number_format($playboy['probability'] / 2 + $playboy['astro_score'] + $playboy['bazi_score'], 2),
                'difficulty' => $woo['difficulty'],
                'rival' => $woo['rival']
            ];
//            }
        }
        $sort = 'bazi_score';// probability astro_score bazi_score
        echo '<table border="1" cellspacing="0" cellpadding="5">
                <thead>
                    <tr>
                        <th>排名</th>
                        <th>姓名</th>
                        <th style="' . ($sort === 'probability' ? 'color:red' : '') . '">渣可能性</th>
                        <th style="' . ($sort === 'astro_score' ? 'color:red' : '') . '">占星渣力值</th>
                        <th style="' . ($sort === 'bazi_score' ? 'color:red' : '') . '">八字渣力值</th>
                        <th style="' . ($sort === 'score' ? 'color:red' : '') . '">渣力值</th>
                        <th colspan="2">追求难度星级</th>
                        <th>潜在竞争对手</th>
                    </tr>
                </thead>
            <tbody>';
//        $res = resort($res, 'probability', 'DESC');
        $res = resort($res, $sort, 'DESC');
//        $res = resort($res, 'bazi_score', 'DESC');
        foreach ($res as $k => $r)
        {
            echo '<tr><td>' . ($k + 1) . '</td>';
            echo '<td>' . $r['name'] . '</td>';
            echo '<td>' . $r['probability'] . '</td>';
            echo '<td>' . $r['astro_score'] . '</td>';
            echo '<td>' . $r['bazi_score'] . '</td>';
            echo '<td>' . $r['score'] . '</td>';
            echo '<td>✨' . number_format($r['difficulty'], 1) . '✨</td>';
            if ($r['difficulty'] === 0)
            {
                echo '<td>不怎么需要追就能在一起</td>';
            } elseif ($r['difficulty'] <= 1)
            {
                echo '<td>轻而易举拿下Ta</td>';
            } elseif ($r['difficulty'] <= 2)
            {
                echo '<td>你追Ta隔层纱</td>';
            } elseif ($r['difficulty'] <= 3)
            {
                echo '<td>追求Ta需要一点勇气哦</td>';
            } elseif ($r['difficulty'] <= 4)
            {
                echo '<td>有难度但不是没希望</td>';
            } elseif ($r['difficulty'] <= 5)
            {
                echo '<td>搞定Ta比登天还难</td>';
            }
            switch ($r['rival'])
            {
                case 1:
                    echo '<td>几乎没有</td>';
                    break;
                case 2:
                    echo '<td>有点多</td>';
                    break;
                case 3:
                    echo '<td>去排队</td>';
                    break;
            }
            echo '</tr>';
        }
        echo '</tbody></table>';
    }

    private function index()
    {
        $this->ipLimit();

        echo '<style>
h4 {
    width: 100%;
    height: 30px;
    line-height: 30px;
    margin: 0;
    padding: 0;
}

label {
    width: 150px;
    height: 22px;
    display: inline-block;
    margin-right: 10px;
    overflow: hidden;
    font-size: 12px;
    line-height: 1.5;
    border: 1px solid #00d8d3;
    border-radius: 11px;
}

input[type="radio"] {
    float: left;
}

input[type="reset"] {
    background-color: #f7f7f7;
    color: #24252a;
    width: 100px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    border: unset;
    border-radius: 10px;
    margin-right: 20px;
}

input[type="submit"] {
    background-color: #00d8d3;
    color: #ffffff;
    width: 150px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    border: unset;
    border-radius: 10px;
}
</style>';
        $tags = Db::table('wechat_backup_07_18_14_43_00.zl1_idea_tag')->where('status', 1)->select();

        echo '<form action="/test/test_logic/idealLover" method="get">';
        echo '<h4>用户信息：</h4>';
        echo '<input type="text" name="uen" value="" placeholder="准了号">';
        echo '<input type="text" name="uid" value="" placeholder="用户编号">';
        echo '<h4>限制与提醒：</h4>';
        echo '只看<input type="tel" name="limit" value="20" placeholder="为空表示不限制数量">个档案，';
        echo '<input type="tel" name="score" value="70" placeholder="为空表示不标记">分及以上的标红';
        $tt = '';
        $sx = '';
        foreach ($tags as $v)
        {
            if ($v['type'] !== $tt)
            {
                $tt = $v['type'];
                switch ($v['type'])
                {
                    case 1:
                        echo '<h4>外貌：</h4>';
                        break;
                    case 2:
                        echo '<h4>性格：</h4>';
                        break;
                    case 3:
                        echo '<h4>表达：</h4>';
                        break;
                    case 4:
                        echo '<h4>事业：</h4>';
                        break;
                    case 5:
                        echo '<h4>财富：</h4>';
                        break;
                    case 6:
                        echo '<h4>感情：</h4>';
                        break;
                    case 7:
                        echo '<h4>人际：</h4>';
                        break;
                }
                $sx = $v['sex'];
            } elseif ($v['sex'] && $sx != $v['sex'])
            {
                echo '<br/>';
                echo '<br/>';
                $sx = $v['sex'];
            }
            switch ($v['sex'])
            {
                case 1:
                    $sex = '(男)';
                    break;
                case 2:
                    $sex = '(女)';
                    break;
                default:
                    $sex = '';
                    break;
            }
            echo '<label>' . $v['name'] . $sex . '<input type="radio" name="type' . $v['type'] . '" value="' . $v['id'] . '"></label>';
        }
        echo '<br/><br/>';
        echo '<input type="reset" value="重置方案">';
        echo '<input type="submit" value="开始计算匹配率">';
        echo '</form>';
    }

    private function idealLover()
    {
        $this->ipLimit();

        $uid = input('uid/d', 0);
        $uen = input('uen/s', '');
        $limit = input('limit/d', 20);
        $score = input('score/d', 0);
        $type1 = input('type1/d', 0);
        $type2 = input('type2/d', 0);
        $type3 = input('type3/d', 0);
        $type4 = input('type4/d', 0);
        $type5 = input('type5/d', 0);
        $type6 = input('type6/d', 0);
        $type7 = input('type7/d', 0);
        $sort = input('sort/d', 0);
        $cid = input('cid/d', 0);
        if ($uid <= 0 && $uen !== '')
        {
            $uid = Db::table('wechat_backup_07_18_14_43_00.app_user')->where('uen', $uen)->value('id');
        }
        if ($uid === 0)
        {
            echo '请准确填写用户编号或准了号';
            exit;
        }
        $tagList = [];
        if ($type1)
        {
            $tagList[] = $type1;
        }
        if ($type2)
        {
            $tagList[] = $type2;
        }
        if ($type3)
        {
            $tagList[] = $type3;
        }
        if ($type4)
        {
            $tagList[] = $type4;
        }
        if ($type5)
        {
            $tagList[] = $type5;
        }
        if ($type6)
        {
            $tagList[] = $type6;
        }
        if ($type7)
        {
            $tagList[] = $type7;
        }
        $where = [
            'uid' => $uid,
            'isself' => 0,
            'year' => ['>', 1900],
            'status' => 1,
//            'id' => 4921747,// 奇
//            'id' => 4921761,// 鼎
//            'id' => 4921746,// 黑
//            'id' => 4923204,
        ];
        // 根据档案袋ID过滤
        if ($cid)
        {
            $rids = Db::table('wechat_backup_07_18_14_43_00.app_recode_cat')->where('cid', $cid)->column('rid');

            $where['id'] = ['in', $rids];
        }
        $userRecord = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where(['uid' => $uid, 'isself' => 1, 'status' => 1])->find();
        $recordList = Db::table('wechat_backup_07_18_14_43_00.app_recode')->where($where)->limit($limit)->select();
        $map = ['status' => 1];
        if (!empty($tagList))
        {
            $map['id'] = ['in', $tagList];
        }
        $link = url('idealLover') . '?uid=' . $uid . '&uen=' . $uid . '&limit=' . $limit . '&score=' . $score . '&type1=' . $type1 . '&type2=' . $type2 . '&type3=' . $type3 . '&type4=' . $type4 . '&type5=' . $type5 . '&type6=' . $type6 . '&type7=' . $type7 . '&cid=' . $cid;
        // 读取数据库中的标签
        $tagNameList = (new zl1IdeaTag())->where($map)->order('id ASC')->column('name,sex,type,id', 'id');

        $data = IdealLover::getInstance()->setUserRecord($userRecord)->setRecordList($recordList)->setidealTypeIdList($tagList)->init();

        echo '<style>
        body {
            margin: 0;
            padding: 0;
        }
        table
        {
            border-collapse: collapse;
            margin: 0 auto;
            text-align: center;
        }
        table td, table th
        {
            border: 1px solid #cad9ea;
            color: #666;
            height: 30px;
        }
        table thead
        {
            position: sticky;
            position: -webkit-sticky;
            top: 0;
            z-index: 2;
        }
        table thead th {
            background: #84ffff;
            font-size: 12px;
        }
        table tbody tr:hover {
            background: #d5f5f5;
        }
        .record-name {
            position: sticky;
            position: -webkit-sticky;
            left: 0;
            background: #aaf5f5;
            width: 160px;
        }
        .name a {
            color: #24252a;
        }
        
        .name a.cur {
            color: #ff0000;
        }
        </style>';


        echo '<h1>' . IdealLover::getInstance()->getError() . '</h1>';

        $tip = '匹配档案数：' . count($recordList) . '，当前检测1900年之后出生的档案，括号中的分值为未处理前的，';

        $tip .= $score > 0 ? '>=' . $score . '分的会标红' : '';

        echo '<table width="100%" border="0" cellpadding="10" cellspacing="0"><thead>';
        echo '<tr><th colspan="' . (count($tagNameList) + 3) . '" align="left">' . $tip . '</th></tr>';
        echo '<tr><th class="record-name">档案名</th><th>序号</th><th class="name"><a class="' . ($sort === 0 ? 'cur' : '') . '"  href="' . $link . '&sort=0">综合匹配率' . ($sort === 0 ? '↓ ' : '') . '</a></th>';

        foreach ($tagNameList as $t)
        {
            switch ($t['sex'])
            {
                case 1:
                    $sex = '(男)';
                    break;
                case 2:
                    $sex = '(女)';
                    break;
                default:
                    $sex = '';
                    break;
            }
            echo '<th class="name"><a class="' . ($sort === $t['id'] ? 'cur' : '') . '" href="' . $link . '&sort=' . $t['id'] . '">' . $t['name'] . $sex . ($sort === $t['id'] ? '↓ ' : '') . '</a></th>';
        }
        echo '<tr></thead><tbody>';

        // 数据进行处理，排序
        foreach ($data as $k1 => $v1)
        {
            $total = 0;
            $itemCountNum = count($v1['result']);
            $goodItemNum = 0;
            $notBadItemNUm = 0;
            foreach ($v1['result'] as $k2 => $v2)
            {
                $total += $v2['score'];
                $v2['score'] >= 40 && $goodItemNum++;
                $v2['ori'] > 0 && $notBadItemNUm++;
                if ($sort && $v2['id'] === $sort)
                {
                    $data[$k1]['sort'] = $v2['score'];
                }
            }
            $data[$k1]['average'] = $total / $itemCountNum;// 计算平均分
//            $probability = ($total / $itemCountNum / 2) + ($notBadItemNUm / $itemCountNum * 30) + ($goodItemNum / $itemCountNum * 20);
            $probability = ($total / $itemCountNum * 0.4) + ($notBadItemNUm / $itemCountNum * 30) + ($goodItemNum / $itemCountNum * 30);
            $data[$k1]['probability'] = $probability;
            if ($sort === 0)
            {
                $data[$k1]['sort'] = $data[$k1]['probability'];
            }
        }
        $resortData = resort($data, 'sort', 'DESC');

        foreach ($resortData as $k3 => $v3)
        {
            echo '<tr>';
            echo '<td class="record-name" title="' . $v3['rid'] . '">' . $v3['name'] . '</td>';
            echo '<td>' . ($k3 + 1) . '</td>';
            echo '<td class="score">' . (int)$v3['probability'] . '%</td>';
            foreach ($v3['result'] as $k4 => $v4)
            {
                if ($score > 0 && $v4['score'] >= $score)
                {
                    echo '<td class="score"><font color="red">' . $v4['score'] . '%</font>' . '<font color="#999" size="1">(' . $v4['ori'] . ')</font>' . ' </td>';
                } else
                {
                    echo '<td class="score">' . $v4['score'] . '%<font color="#999" size="1">(' . $v4['ori'] . ')</font>' . ' </td>';
                }
            }
            echo '</tr>';
        }
        echo '</tbody>';

        echo '</table>';
    }

    protected function ipLimit()
    {
        $ip = $this->request->ip();
        $config = (new AppConfig())->configInfo('relation_research');

        $ipList = explode(',', $config['relation_research_ideal_logic_test_ips']);
        if (!in_array($ip, $ipList, true))
        {
            echo '请联系管理员进行访问';
            exit;
        }
    }

    private function showLogic()
    {
        $data = IdealLover::getInstance()->getLogic();

        foreach ($data as $k1 => $v1)
        {
            $a = 1;
            echo '<h4>' . $v1['name'] . '：</h4>';
            echo '排除的逻辑：<br/>';
            if (!empty($v1['except']))
            {
                foreach ($v1['except'] as $k2 => $v2)
                {

                }
            }

        }
    }
}
